<!DOCTYPE html>
<html>
  <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title><?php echo isset($title) ? $title : '';?></title>
      <!-- 设置缩放 -->
      <meta name="viewport" content="minimal-ui,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
      <!-- IOS中禁用将数字识别为电话号码/忽略Android平台中对邮箱地址的识别 -->
      <meta name="format-detection" content="telephone=no" />
      <!-- windows phone 点击无高光 -->
      <meta name="msapplication-tap-highlight" content="no" />
      <!-- icon -->
      <link rel="shortcut icon" href="<?php echo ADMIN_ICO_PIC;?>" type="image/x-icon"/>
      <!-- css -->
      <link rel="stylesheet" type="text/css" href="<?php echo SYS_LINK;?>admin/css/content.css?v=<?php echo V_CSSJS;?>" />

      <style>
        body .sys_con_box{width:auto;min-width:auto;}
        body .sys_box{overflow:hidden;min-height:600px;}
        .db_backups,.db_recovery{float:left;width:460px;min-height:150px;margin-bottom:20px;border-right:1px solid #ddd;}
        .title{height:30px;line-height:30px;text-align:center;font-size:16px;font-weight:400;}
        .tableB{padding:5px 5px 5px 5px;text-align: center;}
        input[type="checkbox"]{margin-right:10px;}
        .sub_btn {padding: 6px 15px;background: #00BCD4;color: #fff;margin-top: 5px;}
      </style>
  </head>
<body class="noselect">
<?php
$userLevel = isset($userLevel) ? $userLevel : 0;
$powerInfo = isset($powerInfo) ? $powerInfo : powerInfoListDeVal();
?>
<div class="con_box">
    <!-- tab导航 -->
    <?php include SYS_PATH.SYS_APP_PATH.'/admin/views/admin_system/navtab.php';?>
	<!--  -->
	<div class="sys_con_box">
		<div class="sys_box ">
			<div class="db_backups">
				<div class="title">安全清理</div>
                <div class="tableB">
                    <input type="button" value="确认清理文件" class="sub_btn" id="delfile_safe">
                </div>
			</div>
			<div class="db_recovery">
				<div class="title">深度清理</div>
				<div class="tableB">
                    <input type="button" value="确认清理文件" class="sub_btn" id="delfile_depth">
				</div>
			</div>
		
		</div>
	</div>
</div>


</body>
<script language="javascript">
    var cssjsv = '<?php echo V_CSSJS;?>';
    var http_url = '<?php echo SYS_HOST;?>';
    var http_link = '<?php echo SYS_LINK;?>';
    var http_fix = '<?php echo SYS_URL_FIX;?>';
</script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/jquery.min.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/skin.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/common.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>plug/common/function.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript">file_load('info');</script>
<script language="javascript">
    // 页面加载完毕
    window.onload = function () {

    }

    // 加载标识
    var loadFlag = 1;

    // 清理方法
    function clearFun(clearflag, operate){
        $.post('<?php echo SYS_URL_PATH("admin_system_cleardo")?>',{
            clearflag:clearflag,
            operate:operate
        },function(res){
            if(res.code == 10000){
                loadFlag == 1;
                layer.msg('文件清理已完成');
                setTimeout(function(){
                    window.location.reload();
                },2000);
            }else if(res.code == 10001){
                loadFlag == 2;
                layer.msg('正在清理中……,已完成 <font color="#11e1fb" size="3">'+res.rate+' %</font>')

            }else{
                loadFlag == 1;
                layer.msg('失败！稍后再试');
            }
            var regPos = /^[0-9]+.?[0-9]*/; //判断是否是数字。
            if(!regPos.test(res.rate) ){
                loadFlag == 1;
                window.location.reload();
            }
        },'json').error(function(e){
            loadFlag == 1;
            layer.msg('失败！稍后再试');
        });
    }

    /**
     * 刷新进度
     */
    function reloadRate(clearflag){
        setInterval(function(){
            console.log('1');
            if(loadFlag == 2){ clearFun(clearflag, 2);}
        }, 3000);
    }

    // jquery
    $(function(){
        //安全清理
        $('#delfile_safe').on('click',function(){
            if(loadFlag != 1){
                layer.msg('正在清理……');return false;
            }
            layer.confirm('确定清理内存临时文件？', {
                btn: ['确定清理','取消'] //按钮
            }, function(){
                layer.closeAll();
                loadFlag = 2;
                let clearflag = 1;
                clearFun(clearflag, 1);
                reloadRate(clearflag);
            }, function(){

            });
        })
        // 深度清理
        $('#delfile_depth').on('click',function(){
            if(loadFlag != 1){
                layer.msg('正在清理……');return false;
            }
            layer.confirm('当前会永久删除多余文件，历史数据还原时可能会丢失一部分图片等文件，谨慎操作！无需还原之前数据推荐操作。', {
                btn: ['确定清理','取消'] //按钮
            }, function(){
                layer.closeAll();
                loadFlag = 2;
                let clearflag = 2;
                clearFun(clearflag, 1);
                reloadRate(clearflag);
            }, function(){

            });
        })
    })
</script>
</html>